import React, {PropTypes} from 'react'
import {connect} from 'dva'
import {RelativeBox, TableView, TableButton, FilterBox} from '../../components/cor'
function secDome({location, dispatch, secDome}) {
  const {filterBoxShowFlag, loading, list, total, param, filterParam, filter, pageParam, fundList, config} = secDome;
  const actionTypeHead = 'secDome/';
  const tableButtonProps = {
    optList: (()=> {
      return [
        {text: '筛选', icon: 'filter', type: 'filter'}
      ]
    })(), handles: {
      filterHandle: (e) => {
        dispatch({
          type: actionTypeHead + 'filterBoxShowFlagChange',
          payload: {
            filterBoxShowFlag: !filterBoxShowFlag
          }
        });
      }
    }
  };
// 筛选条件生成
  const filterBoxProps = {
    showFlag: filterBoxShowFlag,
    advance: {
      fileds: [],
      handle: function () { // 提交
        dispatch({
          type: actionTypeHead + 'query',
          payload: {
            pageParam: {...pageParam, pageNo: 1},
            param: {...param, ...filterParam}
          }
        });
      },
      reset: function () { // 重置
        dispatch({
          type: actionTypeHead + 'query',
          payload: {
            pageParam: {...pageParam, pageNo: 1}
            , param: {...param, ...filterParam}
          }
        });
      },
      fieldHandle: function (name, value) { // 字段更新
        console.log(name + ':	' + value);
        dispatch({
          type: actionTypeHead + 'setFilterParam',
          payload: {
            name: name,
            value: value
          }
        })
      }
    }
  };
  if (config.filterEle && config.filterEle.length > 0) {
    filterBoxProps.advance.fileds = config.filterEle.map(function (value) {
      if (value.type == 'select') {
        value.options = secDome[value.name]
      }
      return value;
    });
  }
// 列表动态生成
  const tableViewProps = {
    loading: loading,
    columns: [],
    rowSelection: null,
    pageParam: {
      current: pageParam.pageNo,
      pageSize: pageParam.pageSize,
      onShowSizeChange: (current, pageSize) => {
        console.log('Current: ', current, '; PageSize: ', pageSize);
        dispatch({
          type: actionTypeHead + 'query',
          payload: {
            pageParam: {
              pageNo: 1,
              pageSize: pageSize,
            },
            param: {
              ...param,
            }
          }
        });
      },
      onChange: (current) => {
        console.log('Current: ', current);
        dispatch({
          type: actionTypeHead + 'query',
          payload: {
            pageParam: {
              ...pageParam,
              pageNo: current,
            },
            param: {
              ...param,
            }
          }
        });
      }
    }
  };
  if (config.tableHeadEle && config.tableHeadEle.length > 0) {
    tableViewProps.columns = config.tableHeadEle.map(function (value) {
      return value;
    });
    tableViewProps.columns.push({
      title: '操作',
      dataIndex: 'testtststst',
      optType: {
        edit: {
          show: true,
          fn: function () {
          }
        },
        detele: {
          show: true,
          fn: function () {
          }
        }
      },
    })
  }
  return (
    <div className='content-inner corTableMain'>
      <RelativeBox>
        <TableButton {...tableButtonProps}>
          <FilterBox {...filterBoxProps}/>
        </TableButton>
      </RelativeBox>
      <TableView {...tableViewProps} contentMenuProps={null} dataSource={{datas: list, total: total}}/>
    </div>
  )
}
function mapStateToProps({secDome}) {
  return {secDome}
}
export default connect(mapStateToProps)(secDome)
